package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

/**
 * @param
 * @return
 */
@Api(tags = "护理计划相关接口")
@RestController
@RequestMapping("/nursing/plan")
public class NursingPlanController {

    @Autowired
    NursingPlanService nursingPlanService;

    //分页查询所有数据
    @ApiOperation(value = "分页条件查询接口")
    @GetMapping("/search")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "护理计划名称", name = "name", dataType = "string"),
            @ApiImplicitParam(value = "启用状态", name = "status", dataType = "string"),
            @ApiImplicitParam(value = "页码", name = "pageNum", required = true, dataType = "int"),
            @ApiImplicitParam(value = "每页显示条数", name = "pageSize", required = true, dataType = "int")})
    public ResponseResult selectByPage(String name, Integer pageNum, Integer pageSize, Integer status) {
        PageResponse page = nursingPlanService.selectByPage(name, pageNum, pageSize, status);
        return success(page);
    }

    //新增护理计划
    @ApiOperation(value = "新增护理计划接口")
    @PostMapping
    public ResponseResult insertNursingPlan(@RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.insertNursingPlan(nursingPlanDto);
        return success();
    }

    //查询回显
    @ApiOperation(value = "查询回显护理计划接口")
    @GetMapping("/{id}")
    public ResponseResult getByIdPlan(@PathVariable Long id) {
        NursingPlanVo nursingPlanVo = nursingPlanService.getByIdPlan(id);
        return success(nursingPlanVo);
    }

    //修改护理计划
    @ApiOperation(value = "修改护理计划接口")
    @PutMapping("/{id}")
    public ResponseResult selectNursingPlan(@RequestBody NursingPlanDto nursingPlanDto, @PathVariable Long id) {
        nursingPlanService.selectNursingPlan(id, nursingPlanDto);
        return success();
    }

    //删除
    @ApiOperation(value = "删除护理计划接口")
    @DeleteMapping("/{id}")
    public ResponseResult deleteNursingPlan(@PathVariable Long id) {
        nursingPlanService.deleteNursingPlan(id);
        return success();
    }

    //是否禁用
    @ApiOperation(value = "是否禁用护理计划接口")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult isNursingPlan(@PathVariable Long id, @PathVariable Integer status) {
        nursingPlanService.isNursingPlan(id, status);
        return success();
    }

    //查询所有护理计划
    @ApiOperation(value = "查询所有护理计划接口")
    @GetMapping
    public ResponseResult selectALLNusingPlan() {
        List<NursingPlanVo>  nursingPlanVo = nursingPlanService.selectALLNusingPlan();
        return success(nursingPlanVo);
    }


}
